package com.ch.engine.daily.abstractTest;

/**
 * 信用卡支付 - 仅实现接口，不继承抽象类
 * 展示：纯接口实现的灵活性
 *
 * @author wangchunhui
 * @date 2025/1/25
 */
public class CreditCardPay implements PaymentInterface, NotificationInterface {
    
    private String cardNumber;
    private String bankName;
    
    public CreditCardPay(String cardNumber, String bankName) {
        this.cardNumber = cardNumber;
        this.bankName = bankName;
    }
    
    @Override
    public boolean processPayment(double amount) {
        validateAmount(amount); // 使用接口默认方法
        
        System.out.println("\n=== 信用卡支付流程 ===");
        System.out.println("银行：" + bankName);
        System.out.println("卡号：****" + cardNumber.substring(cardNumber.length() - 4));
        System.out.println("支付金额：" + PaymentInterface.formatAmount(amount));
        
        // 模拟银行验证
        if (validateCard()) {
            System.out.println("信用卡支付成功");
            sendSuccessNotification(amount);
            return true;
        } else {
            System.out.println("信用卡验证失败");
            return false;
        }
    }
    
    @Override
    public void sendNotification(String message) {
        System.out.println("银行短信：" + message);
    }
    
    private boolean validateCard() {
        System.out.println("验证信用卡信息...");
        return true; // 模拟验证成功
    }
}